<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">

</head>
<body>
    <div class="layui-container" style="width: 700px;height: 600px;margin-top: 0px;padding-top: 60px;">



        <table class="layui-hide" id="test" lay-filter="test"></table>

    </div>

</body>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="layui/layui.js" charset="utf-8"></script>


    <script type="text/html" id="barDemo">
<!--        <a class="layui-btn layui-btn-xs" lay-event="order">订购</a>-->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>

    <script>

        layui.use('table',function(){

            var table = layui.table;

            table.render({
                elem: '#test'
                , url: '/client/menu/findAll'
                , title: '菜单列表'
                , cols: [
                    [
                        {field: 'id', width: 100, title: '编号', sort: true}
                        , {field: 'name', width: 200, title: '菜品'}
                        , {field: 'price', width: 70, title: '单价'}
                        , {field: 'flavor', width: 100, title: '口味'}
                        , {
                            field: 'tid', width: 100, title: '分类', templet: function (data) {
                                return data.type.name
                            }
                          }
                        , {fixed: 'right', width: 120, title: '操作', toolbar: '#barDemo'}
                    ]
                ]
                , page: true
            });

            table.on('tool(test)',function(obj){
                var data = obj.data;

                if( obj.event === 'order'){
                    layer.location.href="/client/menu/findById/"+data.id;
                }

                if(obj.event === 'delete'){
                    layer.confirm('确定要删除吗？', function(index){
                        $.ajax({
                            url: "/client/menu/deleteById/"+data.id,
                            type: "get",
                            success: function(){
                                alert("删除成功");
                                window.location.href="menu_manage.html";
                            }
                        });
                    })
                }
            })




        })



    </script>
</html>